const axios = require("axios");
const cheerio = require("cheerio");
const Koa = require("koa");
const app = new Koa();
const fs = require("fs");
let titles = "";
const path = require("path");
let css = "";
function getHtml() {
  css = fs.readFileSync(path.join(__dirname, "index.css"));
  const response = fs.readFileSync(
    path.join(__dirname, "学成在线", "study", "02.study.html")
  );

  const $ = cheerio.load(response);
  $(".user").addClass("zksCOlor");
  titles += $(".user").html();
  titles += $(".user img").attr("src");
  titles += $(".user").parent();
  titles += $(".user").prev();
}
app.use(async (ctx, next) => {
  getHtml();
  ctx.body = `<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="keywords" content="zzzksNode+爬虫教程" />
    <title>Document</title>
    <style  type="text/css">
      ${css.toString()}
    </style>
  </head>
  <body>
  
${titles}
   
  </body>
</html>
`;
  await next();
});
console.log(__dirname);

app.listen(1155, () => {
  console.log("http://localhost:1155/");
});
